package com.thb.pay.db.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 实体父类
 */
@Data
public class SuperEntity<T extends Model> extends Model<T> {

    public static final Integer DEFAULT_SORT = 0;

    public static final Integer DEFAULT_NORMAL_FLAG = 0;


    public static final Integer DEFAULT_DELETE_FLAG = 1;

    private Long id;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    private Date updateTime;
    /**
     * 删除标识（0-正常,1-删除） 默认0
     */
    @TableField(value = "del_flag", fill = FieldFill.INSERT)
    private Integer delFlag;

    /**
     * 排序（升序）
     */
    @TableField(value = "sort", fill = FieldFill.INSERT)
    private Integer sort;

    public static <T> T create(Class<T> entity) {
        try {
            return entity.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
